package com.ellricky.baselib.ui.order

import com.andr.common.ui.activity.BaseToolBarActivity
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.ToastUtil
import com.ellricky.baselib.R
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.http.HttpUtils
import com.ellricky.baselib.util.BigIvUtil
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.util.Ext.load
import com.ellricky.baselib.util.NewECallback
import kotlinx.android.synthetic.main.activity_student_works_detail.*

class StudentWorksDetailActivity : BaseToolBarActivity<Void, BasePresenter<Void>>() {

    private val worksId by lazy {
        intent.getIntExtra("id", -1)
    }

    override fun getContentLayout(): Int {
        return R.layout.activity_student_works_detail
    }

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = "作品管理"

        loadWorksDetail()
    }

    private fun loadWorksDetail() {
        if (worksId == -1) {
            ToastUtil.show(this, "作品id不能为空")
            return
        }
        val url = EAppUtil.getApiHost()
        val paramMap: MutableMap<String, String> = HashMap()
        paramMap["action"] = "memberJobInfo"
        paramMap["job_id"] = worksId.toString()
        paramMap["eid"] = LocalCacheUtil.getUid()

        HttpUtils.getInstance().postFrom(
            url, paramMap,
            object : NewECallback<WorksDetail?>(this) {
                override fun onSuccess(data: WorksDetail?, msg: String?) {
                    data?.also { data ->
                        iv_student_work_cover?.load(
                            data.job_image,
                            placeholder = R.drawable.base_bg_image_placeholder
                        )
                        iv_student_work_cover.setOnClickListener {
                            BigIvUtil.jumpBigIvPage(
                                this@StudentWorksDetailActivity,
                                arrayListOf(data.job_image),
                                true,
                                0
                            )
                        }
                        tv_work_create_time?.text = data.job_createtime
                        tv_person?.text = "姓名：${data.log_member_name}   老师：${data.user_name}"
                        tv_eva_desc?.text = data.job_level_info
                        when (data.job_level) {
                            1 -> {
                                tv_eva_title?.text = "作品选为优的理由"
                            }
                            2 -> {
                                tv_eva_title?.text = "作品选为平常的理由"
                            }
                            3 -> {
                                tv_eva_title?.text = "作品选为差的理由"
                            }
                        }
                    }
                }
            })
    }
}